package com.mvu.banana.user.generated;

import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.mvu.banana.common.client.ValueDTO;
import com.mvu.banana.domain.client.Gender;
import com.mvu.banana.user.client.ProfileDTO;
import com.mvu.banana.user.client.SearchProfile;

import java.util.ArrayList;
import java.util.List;

public class SearchProfileDTO extends ValueDTO<SearchProfile>{
  public Gender gender;
  public Integer minAge;
  public Integer maxAge;
  public String city;
  public String name;
  public Boolean hasPicture;
  public List<ProfileDTO> results;

  public SearchProfileDTO(){
  }
  
  public void prepare(SearchProfile p0){
    p0.city = new TextBox();
    p0.city.setName("city");
    p0.gender = new ListBox();
    p0.gender.setName("gender");
    for(Gender e : Gender.values()){
      p0.gender.addItem(p0.getStringValue(e), e.name());
    };
    p0.hasPicture = new CheckBox();
    p0.hasPicture.setName("hasPicture");
    p0.maxAge = new ListBox();
    p0.maxAge.setName("maxAge");
    p0.minAge = new ListBox();
    p0.minAge.setName("minAge");
    p0.name = new TextBox();
    p0.name.setName("name");
  }
  
  public void update(SearchProfile p0){
    p0.setResults(results);
  }
  
  public void copy(SearchProfile p0){
    this.city = p0.city.getValue();
    this.gender = Gender.valueOf(p0.gender.getValue(p0.gender.getSelectedIndex()));
    this.hasPicture = p0.hasPicture.getValue();
    this.maxAge = Integer.valueOf(p0.maxAge.getValue(p0.maxAge.getSelectedIndex()));
    this.minAge = Integer.valueOf(p0.minAge.getValue(p0.minAge.getSelectedIndex()));
    this.name = p0.name.getValue();
  }
  
  public String toString(){
    StringBuilder builder = new StringBuilder();
    builder.append("city=").append(this.city).append(", ");
    builder.append("gender=").append(this.gender).append(", ");
    builder.append("hasPicture=").append(this.hasPicture).append(", ");
    builder.append("maxAge=").append(this.maxAge).append(", ");
    builder.append("minAge=").append(this.minAge).append(", ");
    builder.append("name=").append(this.name).append(", ");
    return builder.toString();
  }

//  public void setResults(List<? extends Profile> profiles) {
//    results = new ArrayList<ProfileDTO>();
//    for(Profile profile : profiles){
//      ProfileDTO dto = new ProfileDTO();
//      dto.name = profile.getName();
//      dto.gender = profile.getGender();
//      results.add(dto);
//    }
//  }
}